<?php

namespace App\Models\Cruise;

use App\Models\BaseModel;
use App\Models\Traits\KfUid;
use Illuminate\Database\Eloquent\Relations\HasOne;

class CruiseOrderProcessModel extends BaseModel
{
    protected $table = 'cruise_order_process';

    use KfUid;

    protected $fillable = [
        'cruiseOrderId',
        'step',
        'status',
        'type',
        'createdByUid',
        'updatedByUid',
    ];

    const PROCESS_CREATED   = 0;
    const PROCESS_SUBMITTED = 1;
    const PROCESS_REVIEWED  = 2;
    const PROCESS_MODIFIED  = 3;
    const PROCESS_COMPLETED = 4;
    const PROCESS_CANCEL    = 5;
    const PROCESS_TRANSFER  = 6;
    const PROCESS_EXT_REVIEWED    = 10;
    const PROCESS_RECEIVE   = 11;
    const PROCESS_SELF_REVIEWED = 12; // 自检督导审核

    const PROCESS_MAPPING = [
        self::PROCESS_CREATED   => '已生成',
        self::PROCESS_SUBMITTED => '已提交',
        self::PROCESS_REVIEWED  => '已审核',
        self::PROCESS_MODIFIED  => '已修改',
        self::PROCESS_COMPLETED => '已完成',
        self::PROCESS_CANCEL    => '已作废',
        self::PROCESS_TRANSFER    => '已转交',
        self::PROCESS_EXT_REVIEWED    => '已审核',
        self::PROCESS_RECEIVE   => '已领取',
        self::PROCESS_SELF_REVIEWED   => '已审核',
    ];

    const PROCESS_PUSH_MAPPING = [
        self::PROCESS_CREATED   => '待生成',
        self::PROCESS_SUBMITTED => '待提交',
        self::PROCESS_REVIEWED  => '待审核',
        self::PROCESS_MODIFIED  => '待修改',
        self::PROCESS_COMPLETED => '待完成',
        self::PROCESS_CANCEL    => '已作废',
        self::PROCESS_TRANSFER    => '已转交',
        self::PROCESS_EXT_REVIEWED    => '待审核',
        self::PROCESS_RECEIVE   => '待领取',
        self::PROCESS_SELF_REVIEWED   => '待审核',
    ];


    const STATUS_OK  = 1;  //同意
    const STATUS_OFF = 2;  //驳回

    const STATUS_GREY = 3;  //灰色

    const STATUS_MAPPING = [
       self::STATUS_OK  => '已同意',
       self::STATUS_OFF => '已驳回',
    ];


    /**
     * 初始化表记录
     * @param string $orderNo
     * @param int $shopId
     * @return \Illuminate\Database\Eloquent\Builder|\Illuminate\Database\Eloquent\Model
     */
    public static function initCruiseOrderProcess(int $cruiseOrderId)
    {
        return self::query()->updateOrCreate(['cruiseOrderId' => $cruiseOrderId, 'step' => self::PROCESS_CREATED],[
            'type'             => CruiseOrderModel::TYPE_NEW_SHOP_HELP,
            'status'           => self::STATUS_OK,
        ]);
    }

    /**
     * @return HasOne
     */
    public function examineLogRel(): HasOne
    {
        return $this->hasOne(CruiseOrderExamineLogModel::class, 'processId', 'id');
    }

}
